package com.atguigu.mvc.controller;

import com.atguigu.mvc.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @版本： V5.1.0
 * @版权： Copyright @ 2025 广东广昱信息科技有限公司版权所有
 * @作者： 广东广昱信息科技有限公司
 * @日期： 2025-06-01 19:44
 */
@Controller
public class ParamController {
    @RequestMapping("/testServletAPI")
    //形参位置requset表示当前请求
    public String testServletAPI(HttpServletRequest request) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        HttpSession session = request.getSession();
        System.out.println("username:" + username + "password:" + password);
        return "success";
    }

    @RequestMapping ("/testParam")
     public String testParam(@RequestParam(value = "user_name",required = false, defaultValue = "admin") String username, String password, String hobby, @RequestHeader("Host")String host) {
        System.out.println("username:" + username + "password:" + password+",hobby:"+hobby);
        System.out.println("host:"+host);
        return "success";
    }

    @RequestMapping("/testBean")
    public String testBean(User user) {
        System.out.println(user);
        return "success";
    }
}
